package edu.fsu.cs.SHPE;

import java.util.ArrayList;
import java.util.Date;

public class Session {
	
	private String title, startTime, endTime, description, room;
	private long id, venueId, materialId, sessionTypeId;
	
	private ArrayList<Long> speakerIds, trackIds;
	private Date stateDate, endDate;
	
	//03/17/2011 06:00:00
	
	public Date getStateDate() {
		return stateDate;
	}


	public void setStateDate(Date stateDate) {
		this.stateDate = stateDate;
	}


	public Date getEndDate() {
		return endDate;
	}


	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}


	public void setSpeakerIds(ArrayList<Long> speakerIds) {
		this.speakerIds = speakerIds;
	}


	public void setTrackIds(ArrayList<Long> trackIds) {
		this.trackIds = trackIds;
	}


	public static Date parseDate(String date){
		Date d = new Date();
		
		d.setMonth(Integer.parseInt(date.substring(0, 2)));
		d.setDate(Integer.parseInt(date.substring(3, 5)));
		d.setYear(Integer.parseInt(date.substring(6, 10)));
		
		d.setHours(Integer.parseInt(date.substring(11, 13)));
		d.setMinutes(Integer.parseInt(date.substring(14, 16)));
		d.setSeconds(Integer.parseInt(date.substring(17, 19)));
		
		return d;
	}
	
	
	/*
	public static void addToCalendar(Context ctx, final String title, final long dtstart, final long dtend) {
	    final ContentResolver cr = ctx.getContentResolver();
	    Cursor cursor ;
	    if (Integer.parseInt(Build.VERSION.SDK) == 8 )
	        cursor = cr.query(Uri.parse("content://com.android.calendar/calendars"), new String[]{ "_id", "displayname" }, null, null, null);
	    else
	        cursor = cr.query(Uri.parse("content://calendar/calendars"), new String[]{ "_id", "displayname" }, null, null, null);
	    if ( cursor.moveToFirst() ) {
	        final String[] calNames = new String[cursor.getCount()];
	        final int[] calIds = new int[cursor.getCount()];
	        for (int i = 0; i < calNames.length; i++) {
	            calIds[i] = cursor.getInt(0);
	            calNames[i] = cursor.getString(1);
	            cursor.moveToNext();
	        }
	 
	        AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
	        builder.setSingleChoiceItems(calNames, -1, new DialogInterface.OnClickListener() {
	 
	            @Override
	            public void onClick(DialogInterface dialog, int which) {
	                ContentValues cv = new ContentValues();
	                cv.put("calendar_id", calIds[which]);
	                cv.put("title", title);
	                cv.put("dtstart", dtstart );
	                cv.put("hasAlarm", 1);
	                cv.put("dtend", dtend);
	 
	                Uri newEvent ;
	                if (Integer.parseInt(Build.VERSION.SDK) == 8 )
	                    newEvent = cr.insert(Uri.parse("content://com.android.calendar/events"), cv);
	                else
	                    newEvent = cr.insert(Uri.parse("content://com.android.calendar/events"), cv);
	 
	                if (newEvent != null) {
	                    long id = Long.parseLong( newEvent.getLastPathSegment() );
	                    ContentValues values = new ContentValues();
	                    values.put( "event_id", id );
	                    values.put( "method", 1 );
	                    values.put( "minutes", 15 ); // 15 minuti
	                    if (Integer.parseInt(Build.VERSION.SDK) == 8 )
	                        cr.insert( Uri.parse( "content://com.android.calendar/reminders" ), values );
	                    else
	                        cr.insert( Uri.parse( "content://calendar/reminders" ), values );
	 
	                }
	                dialog.cancel();
	            }
	 
	        });
	 
	        builder.create().show();
	    }
	    cursor.close();
	}
	*/
	 
	
	public Session(){
		speakerIds = new ArrayList<Long>();
		trackIds = new ArrayList<Long>();
	}
	
	public boolean containsTrackId(long id){
		for(Long l : trackIds)
			if(l.longValue() == id)
				return true;
		
		return false;
	}
	
	public boolean containsSpeakerId(long id){
		for(Long l : speakerIds)
			if(l.longValue() == id)
				return true;
		
		return false;
	}
	
	
	
	public void addSpeakerId(long id){
		speakerIds.add(id);
	}
	
	public void addTrackId(long id){
		trackIds.add(id);
	}
	
	public ArrayList<Long> getSpeakerIds(){
		return speakerIds;
	}
	
	public ArrayList<Long> getTrackIds(){
		return trackIds;
	}
	
	
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getStartTime() {
		return startTime;
	}

	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}

	public String getEndTime() {
		return endTime;
	}

	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getRoom() {
		return room;
	}

	public void setRoom(String room) {
		this.room = room;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public long getVenueId() {
		return venueId;
	}

	public void setVenueId(long venueId) {
		this.venueId = venueId;
	}

	public long getMaterialId() {
		return materialId;
	}

	public void setMaterialId(long materialId) {
		this.materialId = materialId;
	}

	public long getSessionTypeId() {
		return sessionTypeId;
	}

	public void setSessionTypeId(long sessionTypeId) {
		this.sessionTypeId = sessionTypeId;
	}
}
